package com.tmc.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;

import com.tmc.entity.inthotel.ToHotelTbl;

public class UploadOrDownLoad {
	
	public static void writeFile(String strUrl,String fileName,ToHotelTbl hotelTbl){
		URL url = null;
		try{
			url = new URL(strUrl);
		}catch(MalformedURLException e){
			e.printStackTrace();
		}
		InputStream is = null;
		try {
		  is = url.openStream();
		}catch (IOException e) {
		  e.printStackTrace();
		}
		OutputStream os = null;
		String path = "D:\\eclipse_project\\workspace\\staticImgData\\WebRoot\\hotel"+"\\"+hotelTbl.getContinentName()+"\\"+hotelTbl.getCountryName()+"\\"+hotelTbl.getCityName()+"\\"+hotelTbl.getHotelName();
		File f = new File(path);
		f.mkdirs();
		try{
			os = new FileOutputStream(path+"\\"+fileName);
			int bytesRead = 0;
			byte[] buffer = new byte[8192];
			while((bytesRead = is.read(buffer,0,8192))!=-1){
				os.write(buffer,0,bytesRead);
		    }
			System.out.println(fileName+"上传成功");
		}catch(FileNotFoundException e){
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}	
}
